package gameFrame;

import java.awt.*;
import java.awt.event.KeyEvent;

//飞机类
public class plane02 extends GameObject02{
    //定义方向，判断到边界
    //boolean left =true;//要写在重写方法外面，成员变量
    //先定义方向
    boolean left,right,up,down;
    boolean live = true;

//画出来
    @Override
    public void drawMySelf(Graphics g) {

        if(!live){
            return;
        }
        super.drawMySelf(g);
        //移动
        if(left){
            x -=speed;
        }
        if(right){
            x +=speed;
        }
        if(up){
            y -=speed;
        }
        if(down){
            y +=speed;
        }
       /* if(left){
            x -=speed;
        }else {
            x +=speed;
        }
        if(x>GameUtil02.FRAME_WIDTH-30){
            left = true;
        }
        if(x<0){
            left = false;
        }*/
    }
    //按下键盘  在键盘监听类调用
    public void addDirection(KeyEvent e){
        switch (e.getKeyCode()){
            case KeyEvent.VK_LEFT:
                left = true;
                break;
            case KeyEvent.VK_RIGHT:
                right = true;
                break;
            case KeyEvent.VK_UP:
                up = true;
                break;
            case KeyEvent.VK_DOWN:
                down = true;
                break;
        }
    }
    //松开键盘
    public void minusDirection(KeyEvent e){
        switch (e.getKeyCode()){
            case KeyEvent.VK_LEFT:
                left = false;
                break;
            case KeyEvent.VK_RIGHT:
                right = false;
                break;
            case KeyEvent.VK_UP:
                up = false;
                break;
            case KeyEvent.VK_DOWN:
                down = false;
                break;
        }
    }
    public plane02() {
    }

    public plane02(Image img, int x, int y, int speed) {
        super(img, x, y, speed);
    }
}
